package com.sctvcloud.zhaohua_sd.ui.adapter;

import android.content.Context;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.sctvcloud.zhaohua_sd.R;
import com.sctvcloud.zhaohua_sd.base.BaseActivity;
import com.sctvcloud.zhaohua_sd.base.BaseFragment;
import com.sctvcloud.zhaohua_sd.ui.adapter.holder.BaseAbsHolder;
import com.sctvcloud.zhaohua_sd.ui.adapter.holder.Hour24TitleHolder;
import com.sctvcloud.zhaohua_sd.ui.adapter.holder.News24Holder;
import com.sctvcloud.zhaohua_sd.ui.util.IListShowData;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by rh008 on 2017/7/11.
 */

public class NewsListAdapter extends BaseHolderAbsAdapter<IListShowData, BaseAbsHolder<IListShowData>> {

    public static final int VIEWTYPE_TITLE_24 = 7;//24小时的title,第一个的
    public static final int VIEWTYPE_TITLE_24_CONTINUE = 6;//24小时的title,中间的
    public static final int VIEWTYPE_NEWS_24 = 5;//24小时的item
    private BaseActivity activity;
    private BaseFragment fragment;
    private ArrayList<Pair<String, String>> pairs;

    public void setActivity(BaseActivity activity) {
        this.activity = activity;
    }

    public void setFragment(BaseFragment fragment) {
        this.fragment = fragment;
    }

    public void setPairs(ArrayList<Pair<String, String>> pairs) {
        this.pairs = pairs;
    }

    public NewsListAdapter(Context context, List<IListShowData> list) {
        super(context, list);
    }

    @Override
    public BaseAbsHolder<IListShowData> onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseAbsHolder bah = null;
        View v = null;
        switch (viewType) {
            case VIEWTYPE_TITLE_24://24小时的组标题,第一个的
                v = LayoutInflater.from(context).inflate(R.layout.item_title_24_n, parent, false);
                bah = new Hour24TitleHolder(context, v);
                break;
            case VIEWTYPE_TITLE_24_CONTINUE://24小时的组标题,中间的
                v = LayoutInflater.from(context).inflate(R.layout.item_title_24_c_n, parent, false);
                bah = new Hour24TitleHolder(context, v);
                break;
            case VIEWTYPE_NEWS_24://24小时新闻
            default:
                v = LayoutInflater.from(context).inflate(R.layout.item_news_24_cl, parent, false);
                bah = new News24Holder(context, v);
                bah.setPairs(pairs);
                bah.setActivity(activity);
                bah.setFragment(fragment);
                break;
        }
        return bah;
    }

    @Override
    public int getItemViewType(int position) {
        return data.get(position).getDataViewType();
    }

    @Override
    public void onBindViewHolder(BaseAbsHolder<IListShowData> holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.setItemMode(position == getItemCount() - 1 ? BaseAbsHolder.ITEMMODE_LAST : BaseAbsHolder.ITEMMODE_NORMAL);
    }
}
